﻿using Prompts.Prompting.Construction;
using Prompts.Prompting.Construction.Implementation;
using Prompts.Prompting.Model;
using Prompts.Prompting.ViewModels;
using Prompts.Prompting.ViewModels.Implementation;
using Prompts.Prompting.ViewModels.Search.Implementation;

namespace Prompts
{
    public class CasscadingSearchContainer
    {
        private const string SearchWildcard = "*";

        public IPromptBuilder Create()
        {
            return new CasscadingSearchShoppingCartBuilder(
                new PromptItemProvider()
                , CreateCasscadingSearchProvider());
        }

        private ICasscadingSearchProvider CreateCasscadingSearchProvider()
        {
            return CreateCasscadingSearchProvider(CreateAsynchronousSearchService());
        }

        protected virtual ICasscadingSearchProvider CreateCasscadingSearchProvider(
            IAsynchronousSearchServiceBuilder asynchronousSearchServiceBuilder)
        {
            return new CasscadingSearchProvider(asynchronousSearchServiceBuilder);
        }

        private static IAsynchronousSearchServiceBuilder CreateAsynchronousSearchService()
        {
            return new AsynchronousSearchServiceBuilder(
                SearchWildcard
                , CreateChildPromptItemService()
                , new SearchProvider());
        }

        private static IChildPromptItemService CreateChildPromptItemService()
        {
            return new ChildPromptItemService(
                ServiceInjector.Inject<IChildPromptLevelServiceClient>()
                , new PromptItemCollectionBuilder());
        }
    }
}
